<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>down</title>
    <link rel="stylesheet" href="../../plugins/elementui/index.css">
    <link rel="stylesheet" href="../../plugins/font-awesome/css/font-awesome.min.css">
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 40px;
        }
        h2 {
            color: #333;
        }
        input[type="text"] {
            width: 80%;
            padding: 10px;
            font-size: 16px;
        }
        input[type="submit"] {
            padding: 10px 20px;
            font-size: 16px;
            cursor: pointer;
        }
        .result {
            margin-top: 20px;
            padding: 15px;
            background-color: #f9f9f9;
            border: 1px solid #ddd;
            word-break: break-all;
        }
         .el-icon-exit  {
             position: absolute; /* 或 fixed（固定位置不随滚动变化） */
             top: 20px;
             right: 20px;
             background-color: #ff4d4d;
             color: white;
             padding: 10px 15px;
             text-decoration: none;
             border-radius: 5px;
             box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
             font-weight: bold;
             transition: background-color 0.3s ease;
         }

        .el-icon-exit :hover {
            background-color: #cc0000;
        }

    </style>
</head>
<body>
    <h2>文件下载工具</h2>

    <form action="${pageContext.request.contextPath}/fileService/download" method="post">
        <label for="url">请输入要下载的文件URL：</label><br><br>
        <input type="text" id="url" name="url" placeholder="例如：https://example.com/file.zip" required>
        <input type="submit" value="开始下载">
    </form>

    <!-- 显示下载结果 -->
    <div class="result">
        <strong>下载完成！你可以通过以下链接访问文件：</strong><br>
        <a href="" id="downUrl" target="_blank"></a>
    </div>

    <a class="el-icon-exit" href="${pageContext.request.contextPath}/commService/exitU">退出登录</a>

<script src="../../js/vue.js"></script>
<script src="../../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../../js/jquery.min.js"></script>
<script src="../../js/axios-0.18.0.js"></script>
<script>
    document.querySelector("form").addEventListener("submit", function (e) {
        e.preventDefault(); // 阻止表单默认提交行为

        const urlInput = document.getElementById("url");
        const url = urlInput.value;

        axios.post('${pageContext.request.contextPath}/fileService/download', {
            url: url,
            // 'Content-Type': 'application/x-www-form-urlencoded'
        }).then(function (response) {
            console.log('响应数据:', response.data.msg);
            // 展示下载结果
            const downUrlLink = document.getElementById("downUrl");
            downUrlLink.textContent = response.data.msg;
            downUrlLink.href = '';

        }).catch(function (error) {
            console.error('请求失败:', error);
            alert('下载失败: ' + error.response?.data || error.message);
        });
    });
</script>

</body>
</html>
